package com.hiro.framework.tilegame.view;

import java.awt.Color;
import java.awt.event.KeyEvent;

import com.egghiro.framework.j2se.game.core.view.canvas.SGameCanvas;
import com.egghiro.framework.j2se.game.core.view.canvas.SGraphics;
import com.hiro.framework.tilegame.controller.system.STileGameSystem;
import com.hiro.framework.tilegame.model.actor.ITileBoard;


public class STileGameCanvas extends SGameCanvas{

    // private final ScreenState WAITING_FOR_KEY_STATE = new WaitingForKeyState();
    // private final AnimationState ANIMATION_STATE = new AnimationState();
    // private final GameClearState GAME_CLEAR_STATE = new GameClearState();
    private ITileBoard tiles = null;

    public STileGameCanvas(int width, int height, ITileBoard tiles) {
        super(width, height);

        this.tiles = tiles;
        this.tiles.registerFrameObserver(this);
    }

//    @Override
//    public void setKeyListener() {
//        removeKeyListener(this.state);
//        addKeyListener(this.state);
//    }

    @Override
    public void keyPressed(KeyEvent e) {
       STileGameSystem.getInstance().keyPressed(e);
//        for (KeyListener keyListener : getKeyListeners()) {
//            if (keyListener != this) {
//                keyListener.keyPressed(e);
//            }
//        }
    }

    @Override
    public void paint(SGraphics g) {
        g.setBackground(Color.WHITE);
        g.clearRect(0, 0, getHeight(), getHeight());
        tiles.paint(g);
    }

}
